//
//  ACAssetAccessManager.h
//  AlbumFetch
//
//  Created by 黄志明 on 2017/2/6.
//  Copyright © 2017年 黄志明. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <Photos/Photos.h>

typedef NS_ENUM(NSInteger, ACAuthorizationStatus) {
    ACAuthorizationStatusNotDetermined = 0,
    ACAuthorizationStatusRestricted,
    ACAuthorizationStatusDenied,
    ACAuthorizationStatusAuthorized,
};

// 过滤项
typedef NS_OPTIONS(NSInteger, ACAssetMediaType) {
    ACAssetMediaTypePhoto = 1 << 0,
    ACAssetMediaTypeVideo = 1 << 1,
    ACAssetMediaTypeAudio = 1 << 2,
};

@class ACAssetModel, ACAlbumModel;
@interface ACAssetAccessManager : NSObject

+ (instancetype)sharedManager;

/// Return YES if Authorized 返回YES如果得到了授权
- (BOOL)authorizationStatusAuthorized;

// 照片库的授权状态
- (ACAuthorizationStatus)authorizationStatus;

// 获取所有只包含照片相册信息
- (void)fetchAllPhotoAlbum:(void(^)(NSArray <ACAlbumModel *> *photoAlbum))completionBlock;

// 获取所有只含视频的相册信息
- (void)fetchAllVideoAlbum:(void(^)(NSArray <ACAlbumModel *> *photoAlbum))completionBlock;

// 获取所有只含音频的相册信息
- (void)fetchAllAudioAlbum:(void(^)(NSArray <ACAlbumModel *> *photoAlbum))completionBlock;

// 获取含有指定类型文件的相册信息
- (void)fetchAssetAlbum:(ACAssetMediaType)mediaType completion:(void(^)(NSArray <ACAlbumModel *> *photoAlbum))completionBlock;

// 获取所有相册内的所有asset
- (void)fetchAllAssetsFromFetchResult:(ACAlbumModel *)albumModel assetType:(ACAssetMediaType)mediaType completion:(void(^)(NSArray <ACAssetModel *> *photos))completionBlock;

// 获取相册封面照片
- (PHImageRequestID)postImageWithAlbum:(ACAlbumModel *)albumModel size:(CGSize)imageSize completion:(void(^)(UIImage *posterImage))completionBlock;

// 获取相册图片，传size会返回以size为大小的图片  ios8 以后返回的PHImageRequestID 可用于取消获取的请求
- (PHImageRequestID)fetchImageInAsset:(id)asset size:(CGSize)size completion:(void (^)(UIImage *photo,NSDictionary *info, BOOL isDegraded))completion;

// 获取相册大图-fullscreen图片
- (PHImageRequestID)fetchFullScreenImageInAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;

// 取消获取图片的请求 iOS8以后有效
- (void)cancelFetchReqeust:(PHImageRequestID)imageRequestID;

// 根据类型，获取group（相册）实体
- (void)fetchAllAssetAlbum:(ACAssetMediaType)assetMediaType completion:(void (^)(NSArray <ACAlbumModel *> *photoAlbum))completionBlock;

// 根据类型，获取group（相册）内的所有asset(照片、视频、音频 实体)
- (void)fetchAllAssetsFromGroupResult:(ACAlbumModel *)albumModel assetMediaType:(ACAssetMediaType)assetMediaType completion:(void(^)(NSArray <ACAssetModel *> *photos))completionBlock;

// 根据Id获取Asset ios8 以前 assetIdentifier 是ALAsset的 ALAssetPropertyAssetURL ios8以后是PHObject的localIdentifier
- (void)fetchAssetWithIdentifier:(id)assetIdentifier withAlbumIdentifier:(NSString *)albumIdentifier complete:(void (^)(ACAssetModel *assetModel))completionBlock;

// 保存图片到相册
- (void)savePhotoToAlbum:(UIImage *)image completion:(void (^)(ACAssetModel *assetModel))completeion;

// 保存视频到相册
- (void)saveVideoToAlbum:(NSURL *)videoURL completion:(void (^)(ACAssetModel *assetModel))completion;

// 获取从UIImagePickerController选中的原始或者经过裁剪视频信息
- (void)fetchAssetWithReferenceURL:(NSURL *)referenceURL mediaURL:(NSURL *)mediaURL complete:(void (^)(ACAssetModel *assetModel))completionBlock;


@end
